const express = require("express");
// const cors = require("cors"); //引入cors
const app = express();
// const http = require("http");
const mysql = require("mysql");

const pool = mysql.createConnection({
  host: "121.196.210.117", //MySQL服务器地址
  port: 3306, //MySQL服务器端口号
  user: "root", //数据库用户的用户名
  password: "123456", //数据库用户密码
  database: "hand-purchase", //数据库名称
  connectionLimit: 20, //最大连接数
  charset: "utf8", //数据库服务器的编码方式
});
// console.log(pool);
// 创建服务器对象
pool.connect();
app.use(express.urlencoded({ extended: true }));

app.listen(3000, () => {
  console.log("成功监听端口3000");
});

app.post("/login", (req, res) => {
  console.log(req.body);
  let u = req.body.uname;
  let p = req.body.upwd;
  let sql = "select uid from zm_user where uname=?&&upwd=?";
  pool.query(sql, [u, p], (err, r) => {
    if (err) throw err;
    r.length ? res.send("登陆成功") : res.send("账号密码错误");
  });
});
